<%@page import="java.util.ArrayList"%>
<%@page import="entity.Banji"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert_page</title>
</head>
<body>
	<%
     	List<Banji> list = (ArrayList<Banji>)request.getAttribute("list");
     %>

	<form id="ajax_form" method="post" onsubmit="return false">
		名字：<input type = "text" name = "student_name"/><br/>
		年龄： <input type = "text" name = "student_age"/><br/>
		性别：<input type = "text" name = "gender"/><br/>
		班级：<select name="class_id">
				<option>---- 请选择 ----</option>
				<%
					for (Banji banji : list) {
				%>
						<option value="<%=banji.getId()%>"><%=banji.getName()%></option>
				<%
					} 
				%>
			</select> 
			<br/>
			<input type = "button" onclick="submitForm()" value = "添加">
	</form>
	
	<script src="static/js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
	<script src="static/layer-v3.1.1/layer/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="static/mylayer.js" type="text/javascript" charset="utf-8"></script>
    <script src="static/util.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function submitForm(){
			$.ajax({
				url : "${pageContext.request.contextPath}/student?method=insert",
				type : "post",
				dataType : "json",
				data : $("#ajax_form").serialize(),
				success : function(jsonObj){
					console.log(jsonObj);
					if(jsonObj.cod == util.SUCCESS){
						mylayer.success(jsonObj.msg);
						var index = parent.layer.getFrameIndex(window.name);
						setTimeout(function(){
							parent.layer.close(index);
							window.parent.location.reload();
						},1000);
					}else{
						mylayer.error(jsonObj.msg);
					}
				}
			});
		}
		/* $(function(){
			$.post(
				"/ST_JavaEE/student?method=selectClass",
				function(jsonArray){
					console.log(jsonArray);
					$(jsonArray).each(function(){
						var html = "<option value ='"+this.id +"'>"+ this.name+"</option>";
						$("#class_id").append(html);
					});
				},
				"json"
			);
		}); */
		
	</script>
</body>
</html>